package main.Q1501_1600;

public class Q1581_1590 {
    public static void main(String[] args) {
        System.out.println("Question1581：");
        System.out.println("Question1582：");
        System.out.println("Question1583：");
        System.out.println("Question1584：");
        System.out.println("Question1585：");
        System.out.println("Question1586：");
        System.out.println("Question1587：");
        System.out.println("Question1588：所有奇数长度子数组的和");
        int[] arr={1,4,2,5,3};
        System.out.println(new Question1588().sumOddLengthSubarrays(arr));
        System.out.println("Question1589：");
        System.out.println("Question1590：");
    }
}

class Question1588{
    public int sumOddLengthSubarrays(int[] arr) {
        int sum = 0;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            int leftCount = i, rightCount = n - i - 1;
            int leftOdd = (leftCount + 1) / 2;
            int rightOdd = (rightCount + 1) / 2;
            int leftEven = leftCount / 2 + 1;
            int rightEven = rightCount / 2 + 1;
            sum += arr[i] * (leftOdd * rightOdd + leftEven * rightEven);
        }
        return sum;
    }
}